//
//  HECommentScoreCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/10.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HECommentScoreCell.h"
#import "HDRatingStarView.h"

@interface HECommentScoreCell ()

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) HDRatingStarView *startView;


@end

@implementation HECommentScoreCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.qmui_borderPosition = QMUIViewBorderPositionBottom;
        self.qmui_borderWidth = 1;
        self.qmui_borderColor = CSplitLineColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _titleLb = [UILabel new];
    _titleLb.text = @"期待您的5星好评：";
    _titleLb.font = DYFont(16);
    [self.contentView addSubview:_titleLb];
    
    // 星星评分
    _startView = [[HDRatingStarView alloc] init];
    _startView.renderColor = KHexColor(@"F67605");
    _startView.defaultColor = KHexColor(@"CDCDCD");
    _startView.allowTouchToSelectScore = YES;
    _startView.score = 5;
    _startView.countForOneStar = 1;
    _startView.starWidth = 18;
    _startView.starImage = IMAGE_NAMED(@"rating_sel");
    [self.contentView addSubview:_startView];
    
    __weak typeof(self) weakSelf = self;
    _startView.selectScoreHandler = ^(CGFloat score) {
        weakSelf.formModel.cm_score = score;
    };
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-15);
    }];
    
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_startView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLb);
        make.left.equalTo(_titleLb.mas_right).mas_offset(5);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.height.mas_offset(18);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    _startView.score = formModel.cm_score;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
